package com.daikuan.fffkuaiban.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.daikuan.fffkuaiban.R;
import com.daikuan.fffkuaiban.bmobBean.RecListBean;
import com.daikuan.fffkuaiban.utils.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jiming1 on 2017/7/1.
 */
public class GridViewAdapter extends BaseAdapter {

    private Context context;
    private List<RecListBean> recListBeens;

    public GridViewAdapter(Context context, List<RecListBean> recListBeens) {
        this.context = context;
        this.recListBeens = recListBeens;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public RecListBean getItem(int i) {
        return recListBeens.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        BaseViewHolder viewHolder = null;
        final RecListBean recListBean = getItem(i);
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_remen_daikuan, viewGroup, false);
            viewHolder = new BaseViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (BaseViewHolder) view.getTag();
        }

        if (recListBean.hot_logo == null) {
            ImageLoader.loadImage(context, "", viewHolder.imageView);
        } else {
            ImageLoader.loadImage(context, recListBean.hot_logo.url, viewHolder.imageView);
        }
        viewHolder.tvName.setText(recListBean.hot_name);
        viewHolder.tvQuotaRange.setText(recListBean.money_range);
        return view;
    }


    class BaseViewHolder {
        @Bind(R.id.imageView)
        ImageView imageView;
        @Bind(R.id.tvName)
        TextView tvName;
        @Bind(R.id.tvQuotaRange)
        TextView tvQuotaRange;

        public BaseViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


}
